package network;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.nio.ByteBuffer;

public class Packet_Alive extends Packet {

	public Packet_Alive(int timestamp)
	{
		m_type=packettype.ALIVE;	
		m_timestamp=timestamp;	
	}
	
	public Packet_Alive(DatagramPacket packet) 
	{	
		m_address=packet.getAddress();
		m_type=packettype.ALIVE;
		ByteBuffer buffer=ByteBuffer.wrap(packet.getData());
		Header(packet.getAddress(),buffer);
	}
	
	public DatagramPacket Encode(InetAddress address, int port)
	{
		byte []buffer=new byte[1024];
		ByteBuffer BB=ByteBuffer.wrap(buffer);	
		//encode type
		BB.put(getTypebyte(m_type));	
		BB.putInt(m_timestamp);	
		//encode nothing else, alive packet, natch
		
		return new DatagramPacket(buffer,buffer.length,address,port);
	}
}
